class Solution:
    # @param    A       a list of integers
    # @param    elem    an integer, value need to be removed
    # @return an integer
    def removeElement(self, A, elem):
        si = len(A)
        i = 0
        while i < si:
            while si > 0 and A[si-1] == elem:
                si -= 1
            if A[i] == elem:
                A[i] = A[si-1]
                si -= 1
            else:
                i += 1
        return si

if __name__ == '__main__':
    a = [1,2,3,4,3,4,5,6]
    t = 3
    so = Solution()
    n = so.removeElement(a, t)
    x = []
    for i in xrange(n):
        x.append(a[i])
    print x